package com.ex.ui;

import java.awt.EventQueue; 

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import java.awt.BorderLayout;
import javax.swing.JToggleButton;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;

import com.ex.ui.infoframe.PersonInfoIFrame;
import com.ex.ui.infoframe.PersonInfoPanel;
import com.ex.ui.questionpanel.CircleAreaPanel;
import com.ex.ui.questionpanel.HeartAreaPanel;
import com.ex.ui.questionpanel.TriangleAreaPanel;
import com.ex.ui.questionpanel.TriangleJudgePanel;

import javax.swing.JTextField;
import javax.swing.JDesktopPane; 
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.awt.event.ActionEvent;
public class MainWnd {

	private JFrame mFrame; 
	private JMenuItem mTriangleJudgeMenuItem;
	PersonInfoIFrame mPersonFrame;
	private JDesktopPane desktopPane;
	private JMenuItem mPersonInfoMenuItem;
	private JMenuItem mTriangleMenuItem;
	private JMenuItem mCircleMenuItem;
	private JMenuItem mHeartMenuItem;
	private JMenuItem mMixMenuItem;
	private JToggleButton mHeartTb;
	private JToggleButton mTriangleTb;
	private JMenuItem mCloseMenuItem;
	private JToggleButton mSquartTb;
	 
	public void createFrame(JPanel panel)
	{
		MyInternalFrame frm = new MyInternalFrame(panel); 
		frm.setVisible(true);
			desktopPane.add(frm);  
				try {
					frm.setSelected(true);
			} catch (PropertyVetoException e1) { 
				
				e1.printStackTrace();
			}
	} 
	
	
	public class QuestionListener implements ActionListener
	{
		JPanel mQuestionPanel;
	    public QuestionListener(JPanel p)
	    {
	    	mQuestionPanel = p;
	    }
		@Override
		public void actionPerformed(ActionEvent e) {
			createFrame(mQuestionPanel);  
		} 
	}
	
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try { 
					MainWnd window = new MainWnd();
					window.mFrame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainWnd() {
		initialize();
	}

	public void show()
	{
		mFrame.setLocationRelativeTo(null);
		mFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
		mFrame.setVisible(true);
	}
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		mFrame = new JFrame();
		mFrame.setBounds(100, 100, 512, 398);
		mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JMenuBar menuBar = new JMenuBar();
		mFrame.setJMenuBar(menuBar);
		JMenu mnNewMenu = new JMenu("小朋友个人信息");
		menuBar.add(mnNewMenu);		
		mPersonInfoMenuItem = new JMenuItem("基本信息"); 
		mnNewMenu.add(mPersonInfoMenuItem); 
		
		JToolBar toolBar = new JToolBar();		
		mFrame.getContentPane().add(toolBar, BorderLayout.NORTH); 
		desktopPane = new JDesktopPane();
		mFrame.getContentPane().add(desktopPane, BorderLayout.CENTER);  
	 	desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		
		PersonInfoIFrame mPersonFrame = new PersonInfoIFrame(); 
	 	mPersonFrame.setBounds(15, 20, 320, 230);
	 	mPersonFrame.setVisible(true);
	 	mPersonFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
	 	mPersonFrame.getContentPane().setLayout(new BorderLayout()); 
	 	mPersonFrame.setResizable(true);
	 	mPersonFrame.setIconifiable(true);  
	 	
		desktopPane.add(mPersonFrame); 
		 try {
			 mPersonFrame.setSelected(true);
		    } catch (java.beans.PropertyVetoException e) {}
			mPersonInfoMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					createFrame(new PersonInfoPanel(mPersonFrame.mNameLb )); 
				}
			});
			
		 
		JMenu menu = new JMenu("题型");
		menuBar.add(menu); 
		JMenu menu_1 = new JMenu("计算");
		menu.add(menu_1);  
		
		mTriangleMenuItem = new JMenuItem("三角形面积");
		mTriangleMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				createFrame(new TriangleAreaPanel(mPersonFrame)); 
			}
		});
		menu_1.add(mTriangleMenuItem);
		
		mCircleMenuItem = new JMenuItem("圆形面积计算");
		mCircleMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				createFrame(new CircleAreaPanel(mPersonFrame)); 
			}
		});
		menu_1.add(mCircleMenuItem);
		
		mHeartMenuItem = new JMenuItem("心形面积计算");
		mHeartMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				createFrame(new HeartAreaPanel(mPersonFrame)); 
			}
		});
		menu_1.add(mHeartMenuItem); 
		JMenu menu_2 = new JMenu("判定题"); 
		menu.add(menu_2);
		
		mTriangleJudgeMenuItem = new JMenuItem("三角形判断");
		mTriangleJudgeMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {  
				createFrame(new TriangleJudgePanel(mPersonFrame));  
		}	
		});
		 
		menu_2.add(mTriangleJudgeMenuItem);
		mMixMenuItem = new JMenuItem("混合出题");
		mMixMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 JOptionPane.showMessageDialog(mFrame, "这个功能还没有实现！");
			}
		});
		menu.add(mMixMenuItem);
		
		JMenu menu_3 = new JMenu("退出");
		menuBar.add(menu_3);
		
		mCloseMenuItem = new JMenuItem("退出");
		mCloseMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				mFrame.dispose();
			}
		});
		menu_3.add(mCloseMenuItem);
		
		mTriangleTb = new JToggleButton("");
		mTriangleTb.setHorizontalAlignment(SwingConstants.LEFT);
		mTriangleTb.setToolTipText("三角形判断题\r\n");
		mTriangleTb.setIcon(new ImageIcon(MainWnd.class.getResource("/resources/images/toolbar/JDesktop.gif")));
		toolBar.add(mTriangleTb);
		
		mHeartTb = new JToggleButton("");
		mHeartTb.setToolTipText("心型面积周长计算");
		mHeartTb.setIcon(new ImageIcon(MainWnd.class.getResource("/resources/images/toolbar/JDialog.gif")));
		toolBar.add(mHeartTb);
		
		mSquartTb = new JToggleButton("");
		mSquartTb.setToolTipText("正方形面积周长计算");
		mSquartTb.setIcon(new ImageIcon(MainWnd.class.getResource("/resources/images/toolbar/JTable.gif")));
		toolBar.add(mSquartTb);
		
 	
		
	 	
	 	
	}
}
